package com.xr.miniprogram.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.xr.common.annotation.Excel;
import com.xr.common.constant.MiniProgramConstants;
import com.xr.common.core.domain.BaseEntity;
import com.xr.common.enums.UserSex;
import com.xr.miniprogram.domain.vo.MiniProgramUserVO;
import lombok.Data;

import org.springframework.beans.factory.annotation.Value;

import java.util.Date;
@Data
@TableName("mp_user")
public class MiniProgramUser {
    private static final long serialVersionUID = 1L;

    /** 用户id */
    @TableId(type = IdType.AUTO)
    private Long miniProgramUserId;
    /** 手机号 */
    @Excel(name = "手机号")
    private String phone;
    /** 微信标识 */
    @Excel(name = "微信标识")
    private String openId;
    /** 头像地址 */
    @Excel(name = "头像地址")
    private String avatarUrl;
    /** 昵称 */
    @Excel(name = "昵称")
    private String nickName;
    /** 生日 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "生日", width = 30, dateFormat = "yyyy-MM-dd")
    private Date birthday;
    /** 性别 */
    @Excel(name = "性别")
    private Long sex;
    /**
     * 角色权限,0代表普通用户，1代表服务人员，2代表客服人员
     */
    @Excel(name = "角色权限")
    private String roles;

    @Value("${user.avatarPath}")
    @TableField(exist = false)
    private String DEFAULT_AVATAR;
    public static MiniProgramUser buildDefault(String openId){
        if (openId==null){
            return null;
        }
        MiniProgramUser miniProgramUser = new MiniProgramUser();
        miniProgramUser.setNickName("微信用户");
        miniProgramUser.setOpenId(openId);
        miniProgramUser.setAvatarUrl(miniProgramUser.DEFAULT_AVATAR);
        miniProgramUser.setBirthday(null);
        miniProgramUser.setSex(MiniProgramConstants.SEX_UNKNOWN);
        miniProgramUser.setRoles("0");
        return miniProgramUser;
    }
}
